import XmlHttpTool from "./MyTools/XmlHttpTool";
import { platform } from "os";
import PlatformUtil from "./Platforms/PlatformUtil";
// var ChargeCoinItem = cc.Class({
//     name: 'chargeCoinItem',
//     properties: {
//         coinLabelString:cc.String,
//         coinBtnString:cc.String,     
//     }
// });

const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    items : Array<cc.Node> = [];

    @property(cc.Node)
    MessageScroll: cc.Node = null;

    @property(cc.Node)
    CoinCell : cc.Node = null 

    @property([cc.SpriteFrame])
    CoinSignSpriteArray: Array<cc.SpriteFrame> = [];

    // @property(ChargeCoinItem)
    // ChargeListInfo: Array<any> = [];

    @property(cc.Node)
    CoinImage : cc.Node = null 

    @property(cc.Label)
    CoinLabel : cc.Label = null 

    @property(cc.Label)
    BuyLabel : cc.Label = null 

    @property
    priceCash : number = 0;

    @property(cc.Node)
    PaymentPopView : cc.Node = null 
    
    @property()
    ChargeListInfo: Array<any> = [];
    
    // LIFE-CYCLE CALLBACKS:

    onLoad () {

        // if(this.items.length>0){
            this.MessageScroll.removeAllChildren();
        // }
        this.coinList()


    }

    coinList(){

        var that = this
        XmlHttpTool.instance.httpUtils("/orders/get_eggescoin_list", {}, function (successRes) {
          cc.log("充值列表", successRes);
           that.ChargeListInfo=successRes
          for(let i=0; i<successRes.length;i++){

            that.initCoinListShow(successRes[i].eggs_coin,successRes[i].price,i);
          }

        }, function (faileRes) {
          cc.log("充值列表失败", faileRes);
        }, function (errorRes) {
     
        });

    }

    initCoinListShow(eggCoin:string,cashMondy:string,index:number){

            this.CoinImage.getComponent(cc.Sprite).spriteFrame=this.CoinSignSpriteArray[index]
            this.CoinLabel.string=eggCoin
            this.BuyLabel.string="¥"+cashMondy+".00"
            var item = cc.instantiate(this.CoinCell);
            this.MessageScroll.addChild(item);
            for (var key in item.getChildByName("Bg").getChildByName("BuyNode").getComponent("ExButton").clickEvents) {
                item.getChildByName("Bg").getChildByName("BuyNode").getComponent("ExButton").clickEvents[key].customEventData = index
             }
         

    }

    ChargeClick(event,customEventData){

        this.priceCash=this.ChargeListInfo[customEventData].price
        cc.log("充值的金额",this.priceCash)
        var isSandbox= PlatformUtil.platform.isSandbox();
        if(isSandbox){
            PlatformUtil.platform.Alipay(this.priceCash)
        }else{
            this.PaymentPopView.active=true
        }
        
    }

    wxPayClick(){

        PlatformUtil.platform.Wxpay(this.priceCash)
    
    }

    aliPayClick(){

        PlatformUtil.platform.Alipay(this.priceCash)
    
    }

    start () {

       
    }

    // update (dt) {}
}
